home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Info.aspx.cs649
< prev
next >
Wrap
Text File
|
2008-04-01
|
15KB
|
432 lines
//===========================================================================
// This file was modified as part of an ASP.NET 2.0 Web project conversion.
// The class name was changed and the class modified to inherit from the abstract base class
// in file 'App_Code\Migrated\Stub_Info_aspx_cs.cs'.
// During runtime, this allows other classes in your web application to bind and access
// the code-behind page using the abstract base class.
// The associated content page 'Info.aspx' was also modified to refer to the new class name.
// For more information on this code pattern, please refer to http://go.microsoft.com/fwlink/?LinkId=46995
//===========================================================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.Drawing;
using System.Text.RegularExpressions;
using System.IO;
using System.Management;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Web;
using System.Web.Caching;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using GBPVR.Public;
using GBPVR.Backend.Common;
using GBPVRSchedule;
using gbweb.classes;
// For IRecordingService
namespace gbweb
{
/// <summary>
/// Summary description for Info.
/// </summary>
public partial class Migrated_Info : Info
{
protected void Page_Load(object sender, System.EventArgs e)
{
Session["GuideStartTime"] = null;
GetDiskInformation("RecordingsDirectory", lblRecordingStats, imgRecordingUsedSystem, imgRecordingUsedGBPVR, imgRecordingFree);
GetDiskInformation("LiveTVDirectory", lblBufferStats, imgBufferUsedSystem, imgBufferUsedGBPVR, imgBufferFree);
hlLogFile.Text = AppDomain.CurrentDomain.FriendlyName + ".log";
hlLogFile.NavigateUrl = Download.GetDownloadUrl(false, true, Download.InternalFiles.Log);
Schedule scheduleHelper = Global.Schedule;
IList myScheduledRecordings = scheduleHelper.LoadRecordingSchedule();
lblScheduleStatus.Text =
GetScheduleStatus(myScheduledRecordings, "Pending", ScheduledRecording.STATUS_PENDING) + ", " +
GetScheduleStatus(myScheduledRecordings, "In Progress", ScheduledRecording.STATUS_IN_PROGRESS) + ", " +
GetScheduleStatus(myScheduledRecordings, "Available", ScheduledRecording.STATUS_COMPLETED) + ", " +
GetScheduleStatus(myScheduledRecordings, "Failed", ScheduledRecording.STATUS_COMPLETED_WITH_ERROR) + ", " +
GetScheduleStatus(myScheduledRecordings, "Conflict", ScheduledRecording.STATUS_CONFLICT) + ", " +
GetScheduleStatus(myScheduledRecordings, "Reoccurring", ScheduledRecording.STATUS_PLACE_HOLDER) + ", " +
GetScheduleStatus(myScheduledRecordings, "Deleted", ScheduledRecording.STATUS_DELETED);
try
{
GetRecordingStatuses();
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
Response.Write("<!--\n" + ex.ToString() + "\n-->");
}
// create the database connection
using (DbConnection aConnection = Global.GetOpenGBPVRDbConnection())
{
try
{
lblEPGRemaining.Text = GetEPGRemaining(aConnection);
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
Response.Write("<!--\n" + ex.ToString() + "\n-->");
}
try
{
lblCurrentTranscode.Text = GetCurrentTranscode(aConnection);
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
Response.Write("<!--\n" + ex.ToString() + "\n-->");
}
//close the connection
aConnection.Close();
}
}
#region Disk Information
private void GetDiskInformation(string nodeName, Label lblStatus, HtmlImage imgUsedSystem, HtmlImage imgUsedGBPVR, HtmlImage imgFree)
{
string pathName = Global.Config.SelectSingleNode("/settings/" + nodeName).InnerText;
string scope;
string root;
ulong FreeBytesAvailable = 0;
ulong TotalNumberOfBytes = 0;
ulong TotalNumberOfFreeBytes = 0;
bool nonSharedMap = false;
double size = 0;
double free = 0;
if (pathName.StartsWith(@"\\"))
{
scope = pathName.Substring(0, pathName.IndexOf(@"\", 2));
root = Directory.GetDirectoryRoot(pathName);
string shareName = root.Substring(scope.Length + 1);
bool success = GetDiskFreeSpaceEx(root, out FreeBytesAvailable, out TotalNumberOfBytes,
out TotalNumberOfFreeBytes);
if (!success)
{
Logger.Info("Falling through to wmi for free space determination.....");
//throw new System.ComponentModel.Win32Exception();
ManagementObject share = new ManagementObject(scope + @"\root\cimv2", "Win32_Share.Name=\"" + shareName + "\"", null);
try
{
share.Get();
}
catch (Exception ex)
{
lblStatus.Text = "Could not load share info for " + root;
imgFree.Visible = false;
imgUsedGBPVR.Visible = false;
imgUsedSystem.Visible = false;
Logger.Warning(ex.ToString());
share.Dispose();
return;
}
try
{
root = share["Path"].ToString();
}
catch (Exception ex)
{
lblStatus.Text = "Could not load share info for " + root;
imgFree.Visible = false;
imgUsedGBPVR.Visible = false;
imgUsedSystem.Visible = false;
Logger.Warning(ex.ToString());
share.Dispose();
return;
}
share.Dispose();
}
else
{
Logger.Info("Using native win32 call for free space determination.....");
nonSharedMap = true;
}
}
else
{
Logger.Info("Using wmi for free space determination.....");
scope = @"\\.";
root = Directory.GetDirectoryRoot(pathName);
}
if (!nonSharedMap)
{
root = root.Replace(Path.DirectorySeparatorChar.ToString(), string.Empty);
ManagementObject disk = new ManagementObject(scope + @"\root\cimv2", "Win32_LogicalDisk.DeviceID=\"" + root + "\"", null);
try
{
disk.Get();
}
catch (Exception ex)
{
lblStatus.Text = "Could not load disk info for " + Directory.GetDirectoryRoot(pathName);
imgFree.Visible = false;
imgUsedGBPVR.Visible = false;
imgUsedSystem.Visible = false;
Logger.Warning(ex.ToString());
disk.Dispose();
return;
}
size = Convert.ToInt64(disk["Size"]);
free = Convert.ToInt64(disk["FreeSpace"]);
disk.Dispose();
}
else
{
size = Convert.ToInt64(TotalNumberOfBytes);
free = Convert.ToInt64(FreeBytesAvailable);
}
double usedgbpvr = GetDirectorySize(pathName);
double usedsystem = size - free - usedgbpvr;
double freepercent = ((double)free/(double)size) * 100.0;
double usedgbpvrpercent = ((double)usedgbpvr/(double)size) * 100.0;
double usedsystempercent = ((double)usedsystem/(double)size) * 100.0;
string sizeunit = "B";
string freeunit = "B";
string usedgbpvrunit = "B";
string usedsystemunit = "B";
ReduceSIUnit(ref size, ref sizeunit);
ReduceSIUnit(ref free, ref freeunit);
ReduceSIUnit(ref usedgbpvr, ref usedgbpvrunit);
ReduceSIUnit(ref usedsystem, ref usedsystemunit);
lblStatus.Text = Directory.GetDirectoryRoot(pathName) + " " +
size.ToString("0.0") + " " + sizeunit + " Total, " +
free.ToString("0.0") + " " + freeunit + " Free, " +
freepercent.ToString("#0.00") + "% Free";
double barlength = 300;
imgFree.Width = (int)(freepercent * barlength / 100);
imgFree.Visible = imgFree.Width > 0;
imgUsedGBPVR.Width = (int)(usedgbpvrpercent * barlength / 100);
imgUsedGBPVR.Visible = imgUsedGBPVR.Width > 0;
imgUsedSystem.Width = (int)(usedsystempercent * barlength / 100);
imgUsedSystem.Visible = imgUsedSystem.Width > 0;
imgUsedSystem.Attributes["title"] =
usedsystem.ToString("0.0") + " " + usedsystemunit + " Used (System), " +
usedsystempercent.ToString("#0.00") + "%";
imgUsedGBPVR.Attributes["title"] =
usedgbpvr.ToString("0.0") + " " + usedgbpvrunit + " Used (GB-PVR), " +
usedgbpvrpercent.ToString("#0.00") + "%";
imgFree.Attributes["title"] =
free.ToString("0.0") + " " + freeunit + " Free, " +
freepercent.ToString("#0.00") + "%";
}
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
private void ReduceSIUnit(ref double value, ref string unit)
{
int unitpos = 0;
string[] units = new string[] {"", "K", "M", "G", "T", "P"};
while (value > 1024) { value = value / 1024; unitpos++; }
unit = units[unitpos] + unit;
}
private long GetDirectorySize(string pathName)
{
long totalsize = 0;
FileSystemInfo[] infos = (new DirectoryInfo(pathName)).GetFileSystemInfos();
foreach (FileSystemInfo info in infos)
{
long itemsize = 0;
try
{
if (info is FileInfo)
{
itemsize = (info as FileInfo).Length;
}
else if (info is DirectoryInfo)
{
itemsize = GetDirectorySize((info as DirectoryInfo).FullName);
}
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
Response.Write("<!--\n" + ex.ToString() + "\n-->");
}
totalsize += itemsize;
}
return totalsize;
}
#endregion
#region Schedule Status
private string GetScheduleStatus(IList myScheduledRecordings, string name, int status)
{
int count = 0;
foreach (ScheduledRecording scheduledRecording in myScheduledRecordings)
{
if (scheduledRecording.getRecordingStatus() == status) count++;
}
return count + " " + name;
}
#endregion
#region Recording Status
private void GetRecordingStatuses()
{
string[] statuses = GetRecordingService().getTunerStatus();
rptRecordingSource.DataSource = statuses;
rptRecordingSource.DataBind();
}
protected string GetSourceName(RepeaterItem Container)
{
string value = Container.DataItem.ToString();
value = value.Substring(0, value.IndexOf(":"));
if (value == "My Source Name")
return "Capture Source #" + (Container.ItemIndex + 1);
return value;
}
protected string GetSourceStatus(RepeaterItem Container)
{
string value = Container.DataItem.ToString();
value = value.Substring(value.IndexOf(":") + 1);
if (liveTVRegex.IsMatch(Container.DataItem.ToString()))
{
value =
"<a href=\"" + Download.GetDownloadUrl(false, false, Download.InternalFiles.LiveTV, Container.ItemIndex.ToString()) + "\" >" + value + "</a>";
}
return value;
}
#endregion
#region EPG Remaining
string GetEPGRemaining(DbConnection aConnection)
{
// create the command object and store the sql query
string SQLstr = "SELECT MAX(start_time) FROM PROGRAMME";
DbCommand aCommand = aConnection.CreateCommand();
aCommand.CommandText = SQLstr;
aCommand.Connection = aConnection;
//create the datareader object to connect to table
DbDataReader aReader = aCommand.ExecuteReader();
DateTime maxDate = DateTime.MinValue;
while(aReader.Read())
{
maxDate = aReader.GetDateTime(0);
}
//close the reader
aReader.Close();
if (maxDate != DateTime.MinValue)
{
TimeSpan span = maxDate.Subtract(DateTime.Today);
return "You have guide data until " + maxDate.ToShortDateString() +
" (" + span.TotalDays.ToString("0") + " days)";
}
else
{
throw new DataException();
}
}
#endregion
#region Current Transcode
string GetCurrentTranscode(DbConnection aConnection)
{
// create the command object and store the sql query
string SQLstr = "SELECT t.percentage, r.filename FROM TRANSCODE_QUEUE t, " +
"RECORDING_SCHEDULE r WHERE (r.oid = t.scheduled_recording_oid) " +
"AND (t.status = 1)";
DbCommand aCommand = aConnection.CreateCommand();
aCommand.CommandText = SQLstr;
aCommand.Connection = aConnection;
//create the datareader object to connect to table
DbDataReader aReader = aCommand.ExecuteReader();
string labelText = string.Empty;
while(aReader.Read())
{
int percentage = aReader.GetInt32(0);
string filename = aReader.GetString(1);
if (percentage > 100)
percentage = 100;
filename = Path.GetFileNameWithoutExtension(filename);
if (labelText.Length > 0)
labelText = labelText + "<br/>";
labelText = labelText + filename + " : " + percentage + "% Complete";
}
//close the reader
aReader.Close();
if (labelText.Length > 0)
return labelText;
return "There are currently no files being transcoded";
}
#endregion
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}